package sort;

import static net.ftng.commons.lang.utils.MathUtils.randomLong;
import static net.ftng.commons.lang.utils.PrintUtils.println;

import org.junit.Test;

public class BubbleSort {

    public static Long[] sort(final Long[] array) {

        int size = array.length;
        int maxIndex = size - 1;
        for (int i = 0; i < maxIndex; i++) {
            for (int j = i + 1; j < size; j++) {
                long long1 = array[i];
                long long2 = array[j];
                if (long1 > long2) {
                    array[j] = long1;
                    array[i] = long2;
                }
            }
        }
        return array;
    }

    @Test
    public void sort() {

        int size = 10;
        Long[] array = new Long[size];
        for (int i = 0; i < size; i++) {
            array[i] = randomLong(0, size);
        }
        println(array);
        BubbleSort.sort(array);
        println(array);
    }
}
